﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Paper_Management_System
{
    public partial class AddForm : Form
    {
        public bool Mode;
        public MainForm paForm;
        public AddForm()
        {
            InitializeComponent();
        }
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            if (Mode == true)
            {
                if (this.tbxTitle.Text!="")//论文名不能为空
                {                    
                    //添加到容器的函数
                    IContainer.Itm tmp;
                    tmp.Title = tbxTitle.Text;
                    tmp.Author = tbxAuthor.Text;
                    tmp.KeyWords = tbxKeyWords.Text;
                    tmp.Abstract = tbxAbstract.Text;
                    paForm.ctnPaper.Add(tmp);
                    //在主窗口中显示
                    //int ctnIdx = paForm.ctnPaper.GetCount() - 1;//最后一行记录的索引
                    //paForm.grdPapers.Rows.Add();
                    //int curR = paForm.grdPapers.Rows.Count - 2;
                    //paForm.grdPapers[0, curR].Value = paForm.ctnPaper.Get(ctnIdx).Title;
                    //paForm.grdPapers[1, curR].Value = paForm.ctnPaper.Get(ctnIdx).Author;
                    //paForm.grdPapers[2, curR].Value = paForm.ctnPaper.Get(ctnIdx).KeyWords;
                    //paForm.grdPapers[3, curR].Value = paForm.ctnPaper.Get(ctnIdx).Abstract;
                    this.paForm.ReLoadData();
                }
                else
                { }
            }
            else
            {
                IContainer.Itm tmp;
                tmp.Title = tbxTitle.Text;
                tmp.Author = tbxAuthor.Text;
                tmp.KeyWords = tbxKeyWords.Text;
                tmp.Abstract = tbxAbstract.Text;
                int idx = paForm.grdPapers.CurrentRow.Index;
                paForm.ctnPaper.Set(idx, tmp);
                //paForm.grdPapers.CurrentRow.Cells[0].Value = tmp.Title;
                //paForm.grdPapers.CurrentRow.Cells[1].Value = tmp.Author;
                //paForm.grdPapers.CurrentRow.Cells[2].Value = tmp.KeyWords;
                //paForm.grdPapers.CurrentRow.Cells[3].Value = tmp.Abstract;
                this.paForm.ReLoadData();
            }
        }
    }
}
